import Vue from 'vue'
import App from './App.vue'
import router from './router'
import axios from 'axios';
import {filepost,post,fpost,fetch,patch,put,baseurl} from './util/axios/http'
import ElementUI from 'element-ui';
import VueI18n from 'vue-i18n';
import qs from 'qs';
// import AxiosPlugin from './util/AxiosPlugin';
import {message} from './util/msg/resetMessage';
/*引入自定义校验*/
import {ValidatePhone,ValidateHz,ValidateIdCard} from './util/validate/ValidateZdy';
import { messages } from './views/common/i18n';
// 富文本编辑器
import VueQuillEditor from 'vue-quill-editor';
import {has} from './views/common/Permission';
import {getAllDic,
    getDict,
    dateFormatYMD,
    rederDateYMD,
    formValidate
} from './views/common/boot';

//引入nprogress
import NProgress from 'nprogress' // 进度条
import 'nprogress/nprogress.css' //这个样式必须引入


import 'element-theme-chalk';
import 'element-ui/lib/theme-chalk/index.css'; // 默认主题
import './assets/css/fonts/icon.css';
import "babel-polyfill";
import moment from 'moment';

/*百度echarts集成*/
import * as echarts from 'echarts';

Vue.config.productionTip = false
Vue.use(VueI18n);
Vue.use(axios);
Vue.use(ElementUI, {
    size: 'small'
});
Vue.use(echarts);
//DatePicker引入
import {DatePicker} from 'element-ui'
Vue.use(DatePicker);  //使用DatePicker
Vue.use(VueQuillEditor);

//设置axios的基础地址
// axios.defaults.baseURL = process.env.API_URL
// Vue.prototype.$axios = axios;
//定义全局变量
Vue.prototype.$post=post;
Vue.prototype.$fpost=fpost;
Vue.prototype.$fetch=fetch;
Vue.prototype.$patch=patch;
Vue.prototype.$put=put;
Vue.prototype.$qs = qs;
Vue.prototype.$filepost = filepost;
Vue.prototype.$getDict = getDict;
Vue.prototype.$getAllDic= getAllDic;
Vue.prototype.$message = message;
Vue.prototype.$baseurl= baseurl;
Vue.prototype.$dateFormat= moment;
Vue.prototype.$dateFormatYMD= dateFormatYMD;
Vue.prototype.$rederDateYMD= rederDateYMD;
Vue.prototype.$formValidate = formValidate;
Vue.prototype.$echarts = echarts;

Vue.prototype.$validatePhone = ValidatePhone;
Vue.prototype.$validateIdCard = ValidateIdCard;

const i18n = new VueI18n({
    locale: 'zh',
    messages
});



// 简单配置
NProgress.inc(0.2)
NProgress.configure({ easing: 'ease', speed: 500, showSpinner: false })


//使用钩子函数对路由进行权限跳转
router.beforeEach((to, from, next) => {
    NProgress.start();
    const role = localStorage.getItem('ms_userName');
    // console.log(role);
    if (!role && to.path !== '/') {
        next('/');
    } else {
        // 简单的判断IE10及以下不进入富文本编辑器，该组件不兼容
        if (navigator.userAgent.indexOf('MSIE') > -1 && to.path === '/editor') {
            Vue.prototype.$alert('vue-quill-editor组件不兼容IE10及以下浏览器，请使用更高版本的浏览器查看', '浏览器不兼容通知', {
                confirmButtonText: '确定'
            });
        } else {
            next();
        }
    }
});

router.afterEach(() => {
    NProgress.done()
})

new Vue({
    router,
    i18n,
    render: h => h(App)
}).$mount('#app');